#include "visualobjecteditor.h"
#include "document.h"
#include "gameObjects/visualobject.h"
#include "application.h"
#include "editormanager.h"
#include "widgets/editorview.h"
#include "widgets/mainwindow.h"
#include "globaldata.h"
#include "modes/objecteditormode.h"
#include "modes/editormodemanager.h"

using namespace ObjectEditors;

VisualObjectEditor::VisualObjectEditor(EditorManager &em)
	: AbstractEditor("VisualObjectEditor", em)
{
}

void VisualObjectEditor::paint( QPainter& painter )
{
	ACQUIRE_DOC();

	Modes::ObjectEditorMode* pMode = 
		qobject_cast<Modes::ObjectEditorMode*>(Application::instance().modeManager()->currentState());
	Q_ASSERT(pMode);
	
	QPointer<VisualObject> visualObject = qobject_cast<VisualObject*>(pMode->selectedGameObject());
	Q_ASSERT(visualObject);

	if(!visualObject->isAnimation())
	{
		painter.drawImage(0, 0, visualObject->imageData().image());
	}
	else
	{
		const VisualObject::Frames& frames = visualObject->frames();
		Q_ASSERT(frames.size() > 0);

		int currentAnimationFrame = Application::instance().globalData()->currentAnimationFrame();

		painter.drawImage(QPoint(0, 0), visualObject->imageData().image(), 
			frames[currentAnimationFrame]);
	}
	
}